package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Grades;
import com.itheima.pojo.Result;
import com.itheima.service.GradesService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Generated;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/grade")
@Tag(name = "年级模块", description = "年级相关接口")
public class GradeController {

    @Autowired
    private GradesService gradesService;

    @GetMapping
    public Result list(){
        log.info("查询全部年级数据");
        //调用service查询年级数据
        List<Grades> gradesList =  gradesService.list();
        return Result.success(gradesList);
    }

    @GetMapping("/{gradeid}")
    public Result getById(@PathVariable Integer gradeid){
        log.info("根据gradeID查询年级信息, gradeid:{}",gradeid);
        Grades grades = gradesService.getById(gradeid);
        return Result.success(grades);
    }

    /**
     * 删除年级
     * @return
     */
    @DeleteMapping("/{gradeid}")
    public Result delete(@PathVariable Integer gradeid){
        log.info("根据gradeid删除年级:{}",gradeid);
        //调用service删除部门
        gradesService.delete(gradeid);
        return Result.success();
    }

    /**
     * 新增年级
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Grades grades){
        log.info("新增年级: {}" , grades);
        //调用service新增部门
        gradesService.add(grades);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Grades grades){
        log.info("更新年级信息 : {}", grades);
        gradesService.update(grades);
        return Result.success();
    }



}
